package hou.just4fun.SeekGirlFriend.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author houweitao
 * @date 2016年5月13日下午2:48:38
 * @TODO 认识的人；不认识的人
 */

public class Person {
	private Gender gender;
	private int handsome;
	private int wealth;
	private int education;
	private int loversNum;
	private int selfScore;
	private String name;
	private Person lover;
	private Map<String, Integer> loverScoreMap;
	private List<Map.Entry<String, Integer>> sortedLovers;
	private List<String> acknowledge;
	
	// public Person() {
	// double d = Math.random();
	// if (d > 0.48)
	// gender = Gender.male;
	// else
	// gender = Gender.female;
	//
	// random();
	// loverScoreMap = new TreeMap<>();
	// }

	public Person(Gender gender, int id) {
		this.gender = gender;
		if (gender == Gender.male)
			name = "man-" + id;
		else
			name = "woman-" + id;
		random();
		loverScoreMap = new HashMap<>();
		acknowledge = new ArrayList<>();
	}

	public void sortLovers() {
		sortedLovers = new ArrayList<Map.Entry<String, Integer>>(loverScoreMap.entrySet());
		Collections.sort(sortedLovers, new Comparator<Map.Entry<String, Integer>>() {
			public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
				return (o2.getValue() - o1.getValue());
				// return (o1.getKey()).toString().compareTo(o2.getKey());
			}
		});

	}

	public List<Map.Entry<String, Integer>> getSortedLovers() {
		if (loverScoreMap == null)
			return null;
		sortLovers();
		return sortedLovers;
	}

	public void setSortedLovers(List<Map.Entry<String, Integer>> sortedLovers) {
		this.sortedLovers = sortedLovers;
	}

	private void random() {
		handsome = randomInt();
		wealth = randomInt();
		education = randomInt();
		loversNum = (int) (Math.log(randomInt() * handsome * wealth * (11 - education)) + 2);
		selfScore = handsome + education + wealth;
	}

	@Override
	public String toString() {
		return "[Gender:" + gender + ", Name:" + name + ", Handsome:" + handsome + ", Wealth:" + wealth + ", Education:"
				+ education + ", numsCanLove:" + loversNum + "]";
	}

	@Override
	public int hashCode() {
		return name.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Person) {
			if (((Person) obj).getName().equals(name))
				return true;
		}
		return false;

	}

	public List<String> getAcknowledge() {
		return acknowledge;
	}

	public void setAcknowledge(List<String> acknowledge) {
		this.acknowledge = acknowledge;
	}

	public int getSelfScore() {
		return selfScore;
	}

	public void setSelfScore(int selfScore) {
		this.selfScore = selfScore;
	}

	public Person getLover() {
		return lover;
	}

	public void setLover(Person lover) {
		this.lover = lover;
	}

	public void setLoverScoreMap(Map<String, Integer> loverScoreMap) {
		this.loverScoreMap = loverScoreMap;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Map<String, Integer> getLoverScoreMap() {
		return loverScoreMap;
	}

	public void setLoverScoreMap(TreeMap<String, Integer> loverScoreMap) {
		this.loverScoreMap = loverScoreMap;
	}

	private int randomInt() {
		return (int) (10 * Math.random()) + 1;
	}

	public Gender getGender() {
		return gender;
	}

	public void setGender(Gender gender) {
		this.gender = gender;
	}

	public int getHandsome() {
		return handsome;
	}

	public void setHandsome(int handsome) {
		this.handsome = handsome;
	}

	public int getWealth() {
		return wealth;
	}

	public void setWealth(int wealth) {
		this.wealth = wealth;
	}

	public int getEducation() {
		return education;
	}

	public void setEducation(int education) {
		this.education = education;
	}

	public int getLoversNum() {
		return loversNum;
	}

	public void setLoversNum(int loversNum) {
		this.loversNum = loversNum;
	}

	public void perfect() {
		education = education + 5;
		wealth = wealth + 5;
		handsome = handsome + 5;
		selfScore = handsome + education + wealth;
	}

}
